import service from '@/utils/request.js';

const url = '/v1/webrpc/';

const pubFun = (method) => (params, id = 1) => service.post(`/api${url}`, {
  id,
  method,
  params,
});

export const checkResponse = (response) => {
  if (response.Code === 200) {
    return Promise.resolve(response.Result);
  }
  return Promise.reject(response.ErrMsg);
};

export const api = {
  list: pubFun('List'),
  stat: pubFun('Stat'),
  move: pubFun('Move'),
  movedir: pubFun('MoveDir'),
  moveToTrash: pubFun('MoveToTrash'),
  copy: pubFun('Copy'),
  delete: pubFun('Delete'),
  deleteDir: pubFun('DeleteDir'),
  restore: pubFun('Restore'),
};
